package com.wlcj.www;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.ext.plugin.redis.JedisPlugin;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.ext.plugin.quartz.QuartzPlugin;
import com.wlcj.plugin.NutzPlugin;
import com.wlcj.plugin.xmlsql.XmlSqlPlugin;
import com.wlcj.www.aop.IndexInterceptor;
import com.wlcj.www.aop.LoginInterceptor;
import com.wlcj.www.handler.ConfigHandler;
import com.wlcj.www.model.data.Data;
import com.wlcj.www.model.data.DateIndustry;
import com.wlcj.www.model.data.PlatformAttention;
import com.wlcj.www.model.data.PlatformQuestion;
import com.wlcj.www.model.data.Province;
import com.wlcj.www.model.data.ProvinceIndustry;
import com.wlcj.www.model.main.Channel;
import com.wlcj.www.model.main.ChannelExt;
import com.wlcj.www.model.main.Content;
import com.wlcj.www.model.main.ContentExt;
import com.wlcj.www.model.main.Friendlink;
import com.wlcj.www.model.main.Penster;
import com.wlcj.www.model.main.Tag;
import com.wlcj.www.model.navigation.Navigation;
import com.wlcj.www.model.platform.EvalReply;
import com.wlcj.www.model.platform.HotPlatform;
import com.wlcj.www.model.platform.Platform;
import com.wlcj.www.model.platform.PlatformEval;
import com.wlcj.www.model.platform.PlatformEvalExt;
import com.wlcj.www.model.platform.PlatformImg;
import com.wlcj.www.model.platform.PlatformNew;
import com.wlcj.www.model.platform.PlatformPrice;
import com.wlcj.www.model.product.FullProduct;
import com.wlcj.www.model.product.Product;
import com.wlcj.www.model.product.UnfinishedProduct;
import com.wlcj.www.web.IndexAction;
import com.wlcj.www.web.IndexNewAction;
import com.wlcj.www.web.ProductListAction;
import com.wlcj.www.web.data.AttentionAction;
import com.wlcj.www.web.data.DataAction;
import com.wlcj.www.web.navigation.NavigationAction;
import com.wlcj.www.web.news.NewsAction;
import com.wlcj.www.web.news.NewsListAction;
import com.wlcj.www.web.platform.PlatEvalAction;
import com.wlcj.www.web.platform.PlatformAction;
import com.wlcj.www.web.product.ProductAction;

public class Www extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setBaseViewPath("/WEB-INF/jsp/");
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexAction.class);
		me.add("/data", DataAction.class);
		me.add("/data/attention", AttentionAction.class);
		me.add("/productList", ProductListAction.class);
		me.add("/navigation",NavigationAction.class);
		me.add("/platform",PlatEvalAction.class);
		me.add("/platformnew",PlatformAction.class,"/platform");
		me.add("/product",ProductAction.class);
		me.add("/index", IndexNewAction.class);
		me.add("/news", NewsAction.class);
		me.add("/newsList", NewsListAction.class);
	}

	@Override
	public void configPlugin(Plugins me) { 
		loadPropertyFile("config.properties");
		// 配置C3p0数据库连接池插件
		DruidPlugin dp = new DruidPlugin(getProperty("jdbc.url"), getProperty("jdbc.username"), getProperty("jdbc.password"));
		me.add(dp);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		arp.setDevMode(true);
		arp.setShowSql(true);
		arp.addMapping("wd_new_date_industry_data", "date_Industry_data_id", DateIndustry.class);
		arp.addMapping("wd_new_province_industry_data", "province_Industry_data_id", ProvinceIndustry.class);
		arp.addMapping("wd_new_platform_attention", "attention_id", PlatformAttention.class);
		arp.addMapping("wd_new_platform_problem", "problem_id", PlatformQuestion.class);
		arp.addMapping("wd_new_data", "data_id", Data.class);
		arp.addMapping("wd_p_platform", "platform_id", Platform.class);
		arp.addMapping("wd_d_provinces", "provinces_id", Province.class);
		arp.addMapping("jc_channel", "channel_id", Channel.class);
		arp.addMapping("jc_channel_ext", "channel_id", ChannelExt.class);
		arp.addMapping("jc_content", "content_id", Content.class);
		arp.addMapping("jc_content_ext", "content_id", ContentExt.class);
		arp.addMapping("wd_p_product_full", FullProduct.class);
		arp.addMapping("wd_p_product_unfinished", UnfinishedProduct.class);
		arp.addMapping("wd_p_img", "img_id",  PlatformImg.class);
		arp.addMapping("wd_p_hot_platform", "hot_platform_id", HotPlatform.class);
		arp.addMapping("wd_p_price",  PlatformPrice.class);
		arp.addMapping("wlcj_new_navigation",  Navigation.class);//导航
		arp.addMapping("wlcj_new_platform_eval", "platform_evaluation_id",PlatformEval.class);//评价
		arp.addMapping("wlcj_new_platform_eval_ext", "ext_id",PlatformEvalExt.class);
		arp.addMapping("wlcj_new_eval_reply","reply_id", EvalReply.class);
		arp.addMapping("wd_p_product", Product.class);//最新标的
		arp.addMapping("jc_new_penster", "penster_id", Penster.class);
		arp.addMapping("jc_friendlink", "friendlink_id", Friendlink.class);
		arp.addMapping("jc_content_ext", "content_id",ContentExt.class);//资讯页面
		arp.addMapping("wd_p_platform_info", "platform_id", PlatformNew.class);//新版平台
		arp.addMapping("jc_content_tag", "tag_id", Tag.class);//标签
		
		//ioc容器
		NutzPlugin np = new NutzPlugin("com.wlcj.www");
		
		JedisPlugin jp = new JedisPlugin(getProperty("redis.host"), getPropertyToInt("redis.port"), getPropertyToInt("redis.timeout"))
			.config("config.properties");
		//QuartzPlugin qp = new QuartzPlugin("job.properties");
		XmlSqlPlugin xsp = new XmlSqlPlugin();
		dp.start();
		arp.start();
		np.start();
		jp.start();
		xsp.start();
		//qp.start();
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new LoginInterceptor());
		me.add(new IndexInterceptor());
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("basePath"));
		me.add(new ConfigHandler());
	}

}
